/**
 * @author tanbiao
 * @since 2019-11-21 18:56:50
 */
layui.define(['form', 'layedit', 'laydate'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var layedit = layui.layedit;
    var laydate = layui.laydate;

    form.render(null, "zmn-form");
    zmnLayUtil.layFormVerify(form);
    // 自定义验证规则
    form.verify({
        sort: function(value){
            if (!/^[0-9]+$/.test(value)) {
                return "排序值只能是正整数";
            }
        }
    });
    form.on('radio(tariffType)',function (obj){
        if(obj.value == 4){
            $("#priceType_1").prop("checked","checked");
            $("#priceType_2").prop("disabled","disabled");
        }else{
            $("#priceType_2").removeAttr("disabled");
        }
        form.render()
    })

    // 提交
    form.on('submit(zmn-form-submit)', function(obj){
        var openId = layer.open({type: 3});
        var data = obj.field;
        var url = "/service/tariff/addEdit.action";

        $.ajax({
            async: false,
            type: "POST", url: url,
            contentType: "application/json", dataType: "json", data: JSON.stringify(data),
            success:function(result) {
                layer.close(openId);
                if(result.status == 200) {
                    layer.msg(result.message,{time: 1000},()=>{
                        zmnLayUtil.closeThisIframe(parent);
                        // parent.location.reload();
                    });
                } else {
                    layer.msg(result.message, {"icon": 2});
                }
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
                layer.close(openId);
            }
        })
        return false;
    });

    layui.$("#cancleBtn").click(function () {
        zmnLayUtil.closeThisTabsChange('/service/tariff/list.action', parent);
    });

    //对外暴露的接口
    exports('serv_service_tariff_detail', {});
});